package com.rush.manageepac.service.impl;

import com.rush.manageepac.dao.CommunityPeopleDao;
import com.rush.manageepac.entity.CommunityPeople;
import com.rush.manageepac.service.intf.CommunityPeopleService;
import com.rush.manageepac.util.StringUtil;
import com.rush.manageepac.vo.PageBean;
import com.rush.manageepac.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 于zH
 * @data 2022/8/29 9:04
 */
@Service
public class CommunityPeopleServiceImpl implements CommunityPeopleService {
    @Autowired
    private CommunityPeopleDao communityPeopleDao;

    @Override
    public R save(CommunityPeople communityPeople) {
        if (communityPeopleDao.save(communityPeople) > 0) {
            return R.ok();
        } else {
            return R.fail("添加失败");
        }
    }

    @Override
    public R update(CommunityPeople communityPeople) {
        if (communityPeopleDao.update(communityPeople) > 0) {
            return R.ok();
        } else {
            return R.fail("修改失败");
        }
    }

    @Override
    public R delete(int id) {
        if (communityPeopleDao.delete(id) > 0) {
            return R.ok();
        } else {
            return R.fail("删除失败");
        }
    }

    @Override
    public PageBean selectPage(String name, int page, int limit) {
        if(StringUtil.isNotEmpty(name)){
            name="%"+name+"%";
        }else{
            name = null;
        }
        long count = communityPeopleDao.selectCount(name);
        int start = (page - 1)*limit;
        return PageBean.ok(count,communityPeopleDao.selectPage(name, start, limit));
    }
}
